// 统一管理 Chrome Storage 使用的键名与前缀

// 固定键（单点存储）
export const STORAGE_KEYS = {
  SPACES: 'ss',
  ACTIVE_SPACE: 'as',
  USER_PREFERENCES: 'ups',
  APP_CONFIG: 'ac',
} as const;

// 键前缀（分区/命名空间）
export const STORAGE_PREFIXES = {
  FAVICON_CACHE: 'fc-',
  COLLECTION: 'c-',            // c-${collectionId}
  SPACE_COLLECTION_INDEX: 'sci-', // sci-${spaceId}
} as const;

// 组合/解析工具（消灭各处拼串/正则）
export const getFaviconCacheKey = (domain: string): string =>
  `${STORAGE_PREFIXES.FAVICON_CACHE}${domain}`;

export const getCollectionKey = (collectionId: string): string =>
  `${STORAGE_PREFIXES.COLLECTION}${collectionId}`;

export const isCollectionKey = (key: string): boolean =>
  key.startsWith(STORAGE_PREFIXES.COLLECTION);

export const getSpaceCollectionIndexKey = (spaceId: string): string =>
  `${STORAGE_PREFIXES.SPACE_COLLECTION_INDEX}${spaceId}`;

export const isSpaceCollectionIndexKey = (key: string): boolean =>
  key.startsWith(STORAGE_PREFIXES.SPACE_COLLECTION_INDEX);
